//
//  VCSignUp.m
//  Astro
//
//  Created by Trinh Huy Cuong on 11/28/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "VCSignUp.h"
#import "VCAbout.h"
#import "VCAccount.h"

@implementation VCSignUp
@synthesize login;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	self.title = @"Đăng ký";
	
	appDelegate = APP_DELEGATE;
	self.navigationItem.rightBarButtonItem = appDelegate.mainButtonItem;    
	
	[scroll addSubview:mainView];
	[scroll setContentSize:CGSizeMake(320, 460)];
	
//	dateInput = [[VCDateInput alloc] initWithNibName:@"VCDateInput" bundle:nil];
//	[dateInput setDelegate:self];
}

- (IBAction) btClick_signup{
	NSInteger requestResult = [CTServer requestURLSignUpWithUserName:userName.text 
															password:password.text 
															birthday:birthday.text 
															  gender:@"1" 
															andPhone:phone.text];
		
	if (requestResult == 4) {
		[(AstroAppDelegate*)[[UIApplication sharedApplication] delegate] setUserInfo:[CTServer requestURLGetUserWithUserName:userName.text]];

		VCAccount *account = [[VCAccount alloc] initWithNibName:@"VCAccount" bundle:nil];
		account.login = self.login;
		account.signup = self;
		[self.navigationController pushViewController:account animated:YES];
		[account release];		
	}		
}

- (void) viewWillAppear:(BOOL)animated{
	[self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (IBAction) showVCAbout{
	VCAbout *about = [[VCAbout alloc] initWithNibName:@"VCAbout" bundle:nil];
	[self.navigationController pushViewController:about animated:YES];
	[about release];
}

- (IBAction) finishInputText{
	[currentTextField resignFirstResponder];
}

#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
//	[scroll setContentOffset:CGPointMake(0, 100) animated:YES];
	currentTextField = textField;
//	return YES;
	
	if (!dateInput) {
		dateInput = [[VCDateInput alloc] initWithNibName:@"VCDateInput" bundle:nil];
		[dateInput setDelegate:self];
		[self.view addSubview:dateInput.view];
	}
	
	if ([textField tag] == 1) {
		[dateInput setDatePickerMode:DatePickerModeDate];
	}
	else {
		[dateInput setDatePickerMode:DatePickerModeTime];
	}

	[dateInput.view setFrame:CGRectMake(0, 460-252, 320, 252)];
	
	return NO;
}

#pragma mark VCDateInputDelegate
- (void) didRecieveDateFromVCDateInput:(NSString*)outputDate andDateString:(NSString*)_dateStr{
	NSLog(@"DateSTR: %@  - %@", outputDate, _dateStr);
	[birthday setText:outputDate];
}

- (void) didCancelVCDateInput{
	NSLog(@"Cancel");
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
